package com.agent.user.mapper;

import com.agent.user.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * 用户Mapper
 * @author Jeff_Wan
 * @description 用户数据访问层
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据Google ID查询用户
     * @param googleId Google ID
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE google_id = #{googleId}")
    User selectByGoogleId(@Param("googleId") String googleId);

    /**
     * 更新会员信息
     * @param userId 用户ID
     * @param membershipType 会员类型
     * @param subscriptionType 订阅类型
     * @param startDate 开始时间
     * @param endDate 结束时间
     */
    @Update("UPDATE user SET " +
            "membership_type = #{membershipType}, " +
            "subscription_type = #{subscriptionType}, " +
            "subscription_start_date = #{startDate}, " +
            "subscription_end_date = #{endDate} " +
            "WHERE id = #{userId}")
    void updateMembership(@Param("userId") Long userId,
                          @Param("membershipType") String membershipType,
                          @Param("subscriptionType") String subscriptionType,
                          @Param("startDate") LocalDateTime startDate,
                          @Param("endDate") LocalDateTime endDate);

    @Select("SELECT * FROM user_auth WHERE identifier = #{identifier} AND identity_type = #{identityType}")
    User findByIdentifierAndType(
            @Param("identifier") String identifier,
            @Param("identityType") String identityType);
}